#ifndef TC_SINGLETON_HPP
#define TC_SINGLETON_HPP

/** \file Singleton.hpp
 * Declarations for the class template Singleton.
 *
 * (C) Copyright Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Singleton.hpp 111 2006-06-19 03:45:40Z semihc $
 *
 *
 */

#include "Frame.hh"
#include "Assert.hpp"


namespace TC {

// FORWARDS
class SingletonMgr;

  /**
   * The class template that enforces Singleton pattern on a given
   * type.
   * T = Type of the object we want apply Singleton pattern.
   */
  TC_EXPORT template <typename T>
  class Singleton 
  {
  public:
    // STATIC FUNCTIONS
    //! Get the manager of the singleton
    static SingletonMgr* GetManager()
    { return s_Manager; }

    //! Set the manager of the singleton
    static void SetManager(SingletonMgr* mgr)
    {
      TC_ASSERT(0 == s_Manager);
      s_Manager = mgr;
    }
      

    //! Access to only instance through given manager.
    static T& GetInstance();

    //! Get the longevity specifier of this singleton.
    static unsigned GetLongevity();

    //! Set the longevity specifier of this singleton.
    static void SetLongevity(unsigned lgv);


  private:
    // NOT ALLOWED
    Singleton();
    Singleton(const Singleton&);
    void operator=(const Singleton&);

    // STATIC FUNCTIONS
    //! The only instance is destoyed via this method.
    static void DestroyInstance();

    // STATIC MEMBERS
    //! Manager of the singleton. Once set it cannot be changed.
    static SingletonMgr* s_Manager;
      
  }; // end class



} // end namespace


#ifndef TC_TEMPLATE_DEFS_SEPARATE
# include "Singleton.cpp"
#endif


#endif /* Include guard */
